package se.webbzon.boltzmann.menu;

public abstract class MRadioGroup {
	
	// The current value of this radio group
	private Object value;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new radio group with the default value null.**/
	public MRadioGroup() {
		this(null);
	}
	
	/** Creates a new radio group with the given default value.**/
	public MRadioGroup(Object defaultValue) {
		this.value = defaultValue;
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** This method is invoked when the radio group changes its value. **/
	public abstract void onChangeValue(Object value);
	
	/** Returns the current value of this radio group. **/
	public Object getValue() {
		return value;
	}

	/** Sets the value of this radio group. **/
	public void setValue(Object value) {
		if (this.value == null) {
			if (value != null) {
				this.value = value;
				onChangeValue(value);
			}
		} else if (!this.value.equals(value)) {
			this.value = value;
			onChangeValue(value);
		}
	}

}
